/*
Copyright (C) 2008 Matthew Perry

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This libary/program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using BaseTools.Helpers;

namespace BaseTools.Configuration.Parsers
{
	/// <summary>
	/// Ini reader/writer for IConfig
	/// </summary>
	public class IniIConfig : IConfig
	{
		/// <summary>
		/// Creates a new ini reader/writer
		/// </summary>
		public IniIConfig()
		{
		}
		
		/// <summary>
		/// Save the configuration to an ini
		/// </summary>
		/// <param name="filename">The filename</param>
		/// <param name="lst">The ConfigList to write</param>
		public void SaveConfiguration(string filename, ConfigList lst)
		{
			new IniConfig().SaveConfiguration(filename, GenericConverter.ReadApplication(lst));
		}
		
		/// <summary>
		/// Save the configuration to a string
		/// </summary>
		/// <param name="lst">The ConfigList to write</param>
		/// <returns>A string representing the ConfigList</returns>
		public string WriteConfiguration(ConfigList lst)
		{
			return new IniConfig().WriteConfiguration(GenericConverter.ReadApplication(lst));
		}
		
		/// <summary>
		/// Load the configuration from an ini
		/// </summary>
		/// <param name="filename">The filename</param>
		/// <returns>A ConfigList interpreted from the file</returns>
		public ConfigList LoadConfiguration(string filename)
		{
			return GenericConverter.WriteApplication(new IniConfig().LoadConfiguration(filename));
		}
		
		/// <summary>
		/// Load the configuration from a string
		/// </summary>
		/// <param name="data">The data</param>
		/// <returns>A ConfigList interpreted from the string</returns>
		public ConfigList ReadConfiguration(string data)
		{
			return GenericConverter.WriteApplication(new IniConfig().ReadConfiguration(data));
		}
	}
}
